#include <cstdio>

int book[10];
int a[6];

bool check() {
	int n1 = a[0]*100 + a[1]*10 + a[2];
	int n2 = a[3]*100 + a[4]*10 + a[5];
	int book1[10] = {0};
	///////////////////////////////////
	int m1 = a[5] * n1;
	//if (m1 >= 1000 || m1 < 100) return false;
	if (m1 >= 1000) return false;
	int m1a = m1 / 100;
	int m1b = (m1%100) / 10;
	int m1c = m1%10;
	book1[m1a]++; book1[m1b]++; book1[m1c]++;
	for (int i=0; i<=9; i++) {
		if (book[i]+book1[i] > 2) return false;
	}
	//////////////////////////////////
	int m2 = a[4] * n1;
	//if (m2 >= 1000 || m2 < 100) return false;
	if (m2 >= 1000) return false;
	int m2a = m2 / 100;
	int m2b = (m2%100) / 10;
	int m2c = m2%10;
	book1[m2a]++; book1[m2b]++; book1[m2c]++;
	for (int i=0; i<=9; i++) {
		if (book[i]+book1[i] > 2) return false;
	}
	//////////////////////////////////
	int m3 = a[3] * n1;
	//if (m3 >= 1000 || m3 < 100) return false;
	if (m3 >= 1000) return false;
	int m3a = m3 / 100;
	int m3b = (m3%100) / 10;
	int m3c = m3%10;
	book1[m3a]++; book1[m3b]++; book1[m3c]++;
	for (int i=0; i<=9; i++) {
		if (book[i]+book1[i] > 2) return false;
	}
	int s = m1 + m2*10 + m3*100;
	//if (s >= 100000 || s < 10000) return false;
	if (s >= 100000) return false;
	int s1 = s / 10000;
	int s2 = (s%10000) / 1000;
	int s3 = (s%1000) / 100;
	int s4 = (s%100) / 10;
	int s5 = s%10;
	book1[s1]++; book1[s2]++; book1[s3]++; book1[s4]++; book1[s5]++;
	for (int i=0; i<=9; i++) {
		if (book[i]+book1[i] > 2) return false;
	}
	return true;
}

void dfs(int n) {
	if (n >= 6) {
		//printf("BINGO!!!\n");
		if (check()) {
			printf("%d%d%d\n%d%d%d\n", a[0], a[1], a[2], a[3], a[4], a[5]);
		}
		return;
	}
	for (int i=0; i<=9; i++) {
		if (book[i] > 2) continue;
		book[i]++;
		a[n] = i;
		dfs(n+1);
		book[i]--;
	}
}

int main() {
	dfs(0);
	return 0;
}
